package top.zuli.package01.class15;

import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.Date;

public class TestDemo3 {
    @Test
    public void SimpleDateFormatTest() throws Exception{
        //创建日期
        Date date = new Date();
        //将日期格式为字符串
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String result = simpleDateFormat.format(date);
        System.out.println(result);

        //将字符串解析为date对象
        String str = "2022-01-01 01:02:03";
        Date date2 = simpleDateFormat.parse(str);
        System.out.println(date2);
    }
}

/*
public class TestDemo3 {
    @Test
    public void SimpleDateFormatTest() throws Exception{
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String result = simpleDateFormat.format(date);
        System.out.println(result);
        String str = "2022-01-01 01:02:03";
        Date date2 = simpleDateFormat.parse(str);
        System.out.println(date2);
    }
}*/

/*
public class TestDemo3 {
    @Test
    public void SimpleDateFormatTest() throws Exception{
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String result = simpleDateFormat.format(date);
        System.out.println(result);
        String str = "2022-01-01 01:02:03";
        Date date2 = simpleDateFormat.parse(str);
        System.out.println(date2);
    }
}*/

/*
public class TestDemo3 {
    @Test
    public void SimpleDateFormatTest() throws Exception{
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String result = simpleDateFormat.format(date);
        System.out.println(result);
        String str = "2022-01-01 01:02:03";
        Date date2 = simpleDateFormat.parse(str);
        System.out.println(date2);
    }
}*/
